package view;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JOptionPane;

/**
 * Class to convert a String to a Date.
 * @author Sarah George
 * @version Autumn 2012
 */
public class StringToDate {
	
	/**
	 * Field to hold the Date object.
	 */
	private Date my_date;
	
	/**
	 * Empty constructor for a String to Date.
	 */
	public StringToDate() {        
	}

	/**
	 * Method to convert a String to a Date.
	 * @param the_text the String to be converted.
	 * @return my_date the Date that was contained in the String.
	 */
	public Date convert(String the_text) {
		DateFormat df = new SimpleDateFormat("EEE/MM/dd/HH/mm/ss/zzz/YYYY");
		try {            
			my_date = df.parse(the_text);                    
		} catch (ParseException e) { 
			JOptionPane.showMessageDialog(null, "You needed to input the date in the form" + 
											"EEE/MM/dd/HH/mm/ss/zzz/YYYY" + 
							" \n an example : Tue/12/04/16/15/00/PST/2012");
			e.printStackTrace();       
		}
		return my_date;
	}
}//End class String to Date.